package cn.zero.flowspringbootstater.configruation;

import lombok.RequiredArgsConstructor;
import org.springframework.transaction.support.TransactionTemplate;

import java.util.function.Supplier;

/**
 * @author lei
 * @date 2023-03-01 09:43
 */
@RequiredArgsConstructor
public class TransactionManager {

    private final TransactionTemplate template;



    public Boolean exe(Supplier<Boolean> f)
    {
       return template.execute((status) -> {
            try {
                f.get();
                status.flush();
                return true;
            }catch (Exception e)
            {
                status.setRollbackOnly();
                return false;
            }

        });
    }
}
